// JavaScript Document
function dialog(options){
	var args = {
			popLayer:null,									//弹出层的内容,必填
			closeBtn:null,									//关闭按钮
			flg:true,										//是否需要遮罩层,默认为需要
			shadeLayer:document.createElement('div'),		//遮罩层div
			iframeLayer:document.createElement('iframe'),	//遮罩层iframe
			appLayer:$(document.body)					//弹层追加位置，默认为追加到body最后
		}
	var doc = $(document.body),win = $(window);
	options = $.extend(args,options);
	init();
	
	//初始化弹出层
	function init(){
		if(options.flg){
			creatShadeLayer();
		};
		//弹出层位置
		var popWidth = $(options.popLayer).outerWidth(),
			popHeight = $(options.popLayer).outerHeight(),
			popTop = (win.height() - popHeight)*0.5,
			popLeft = (win.width() - popWidth)*0.5;
			scrollHieght = win.scrollTop();
		$(options.popLayer).css({position:'absolute','z-index':9999,top:popTop+scrollHieght,left:popLeft,width:'10px',height:'10px','box-shadow':'0 0 5px #666'}).appendTo(options.appLayer).show().focus().animate({width:popWidth,height:popHeight},300);
		//关闭弹出层
		if(options.closeBtn){
			$(options.closeBtn).bind('click',function(){
				closeLayer();
			})
		}
		//esc键关闭弹出层
		$(document).keypress(function(e){
			if(e.keyCode == 27){
				closeLayer();
			}	
		})
	}
	
	
	//初始化遮罩层
	function creatShadeLayer(){
		var overHeight = Math.max(win.height(),doc.height());
		$(options.iframeLayer).css({border:'0 none',width:'100%',height:overHeight,background:'#000',filter:'alpha(opacity=30)',opacity:'0.3',position:'absolute',top:0,left:0});
		options.shadeLayer.id = 'popShadeLayer';
		if($('#popShadeLayer').length==0){
			$(options.shadeLayer).css({top:0,left:0,width:'100%',height:overHeight,'z-index':9998,background:'#000',filter:'alpha(opacity=30)',opacity:'0.3',position:'absolute'}).append($(options.iframeLayer)).appendTo(doc);
		}else{
			$('#popShadeLayer').show();
		}
	}
	
	//关闭
	function closeLayer(){
		$(options.popLayer).fadeOut();
		$(options.shadeLayer).fadeOut();
	}
	
}
